"""
run_game.py

Created by daspork on 2012-04-21.
Copyright (c) 2012 Knuckledragger Games. All rights reserved.
"""

from euclid import *

from state import State
from testscenenode import TestSceneNode

import projection
import drawing
import scene


class TestState(State):
    def __init__(self, window):
        State.__init__(self, window)
        self.camera = scene.Camera((2,5,-15), (0,1,0))
        self.testSceneNode = TestSceneNode()


    def doInit(self):
        pass


    def doDisplay(self, dt):
        projection.set3D(self.window.Width, self.window.Height)
        self.window.Clear()
        self.camera.Focus()
        self.testSceneNode.Draw()
        
        projection.set2D(self.window.Width, self.window.Height)
        
        ## Draw some 2D shit
        self.window.Swap()
        self.window.Damage()


    def doIdle(self, dt):
        self.testSceneNode.Update(dt)
        self.testSceneNode.fps = self.window.Fps
        


    def doKeyboardDown(self, key, x, y):
        if key == chr(27):
            self.window.Pop()
            
        if key == '8':
            q = Quaternion.new_rotate_axis(0.1, Vector3(1,0,0))
            self.testSceneNode.Transform.Rotate(q)
            
        if key == '2':
            q = Quaternion.new_rotate_axis(0.1, Vector3(-1,0,0))
            self.testSceneNode.Transform.Rotate(q)
            
        if key == '7':
            q = Quaternion.new_rotate_axis(0.1, Vector3(0,1,0))
            self.testSceneNode.Transform.Rotate(q)
            
        if key == '9':
            q = Quaternion.new_rotate_axis(0.1, Vector3(0,-1,0))   
            self.testSceneNode.Transform.Rotate(q)
            
        if key == '4':
            q = Quaternion.new_rotate_axis(0.1, Vector3(0,0,-1))
            #self.testSceneNode.Transform.Rotate(q)
            self.testSceneNode.Transform.Translate(Vector3(-1,0,0))
            
        if key == '6':
            q = Quaternion.new_rotate_axis(0.1, Vector3(0,0,1))   
            #self.testSceneNode.Transform.Rotate(q)
            self.testSceneNode.Transform.Translate(Vector3(1,0,0))
            
        if key == '+':
            self.testSceneNode.Transform.Translate(self.testSceneNode.Transform.Forward)
            
            
        if key == '-':
            self.testSceneNode.Transform.Translate(self.testSceneNode.Transform.Back)
            
            
            